package com.team.ware.service.impl;


import com.team.util.AllRecordsVo;
import com.team.util.ResultBuildVo;
import com.team.util.ResultVo;
import com.team.util.StatusShengJIEnum;
import com.team.ware.mapper.WareMapper;
import com.team.ware.model.WareQueryVo;
import com.team.ware.model.WareVo;
import com.team.ware.service.WareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by 李红历 on 2022/7/15.
 */
@Service
public class WareServiceImpl implements WareService{
    @Autowired
    private WareMapper wareMapper;

    @Override
    public ResultVo queryPage(WareQueryVo wareQueryVo) {
        List<WareVo> wareVoList = wareMapper.queryData(wareQueryVo);
        for(WareVo wareVo:wareVoList){
            Integer status =wareVo.getStatus()?1:0;
            wareVo.setStatusName(StatusShengJIEnum.queryNameById(status));
        }
        int count = wareMapper.queryCount(wareQueryVo);
        AllRecordsVo allRecordsVo =new AllRecordsVo();
        allRecordsVo.setDataList(wareVoList);
        allRecordsVo.setPageIndex(wareQueryVo.getPageIndex());
        allRecordsVo.setPageSize(wareQueryVo.getPageSize());
        allRecordsVo.setTotalNumber(count);
        allRecordsVo.setTotalPage(allRecordsVo.countPage(count));
        return ResultBuildVo.success(allRecordsVo);
    }
}
